package com.mvd.app.activity;


import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import com.kongzue.dialog.interfaces.OnMenuItemClickListener;
import com.kongzue.dialog.util.TextInfo;
import com.kongzue.dialog.v3.BottomMenu;
import com.kongzue.dialog.v3.WaitDialog;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.mvd.app.R;
import com.mvd.app.ac2019.AdvanceSettingActivity;
import com.mvd.app.adapter.MyAccountModeListAdapter;
import com.mvd.app.adapter.MyProvincesListAdapter;
import com.mvd.app.application.BaseApplication;
import com.mvd.app.commons.CommonUtils;
import com.mvd.app.commons.Constants;
import com.mvd.app.commons.PDALogUtils;
import com.mvd.app.commons.SharedPreferencesUtils;
import com.mvd.app.commons.UtilsLog;
import com.mvd.app.model.IPPortModel;
import com.mvd.app.model.SettingModel;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @Description: 系统设置
 * @time 2017/6/13
 */
public class SettingActivity extends BaseActivity implements AdapterView.OnItemClickListener {
    //region
    @BindView(R.id.ac_setting_et_ip)
    EditText acSettingEtIp;
    @BindView(R.id.ac_setting_et_port)
    EditText acSettingEtPort;
    @BindView(R.id.ac_setting_et_jiqima)
    EditText acSettingEtJiqima;
    //    Button acSetBtnCancle;
    @BindView(R.id.ac_set_view_m)
    TextView acSetViewM;
    @BindView(R.id.ac_set_btn_save)
    Button acSetBtnSave;
    @BindView(R.id.ac_setting_et_ip_file)
    EditText acSettingEtIpFile;
    @BindView(R.id.ac_setting_et_port_file)
    EditText acSettingEtPortFile;
    @BindView(R.id.ac_setting_txt_moren)
    TextView acSettingTxtMoren;
    @BindView(R.id.textView6)
    TextView textView6;
    @BindView(R.id.ac_setting_set_gaoji)
    RelativeLayout acSettingSetGaoji;
    @BindView(R.id.ac_set_btn_cancle)
    Button acSetBtnCancle;
    @BindView(R.id.ac_setting_38900)
    Switch acSetting38900;
    @BindView(R.id.ac_setting_xin_shengji)
    Switch acSettingXinShengji;
    @BindView(R.id.ac_setting_list_ui)
    Switch acSettingListUi;
    @BindView(R.id.ac_setting_dongtai_paizhao)
    Switch acSettingDongtaiPaizhao;
    @BindView(R.id.ac_setting_raoche_yizhou)
    Switch acSettingRaocheYizhou;
    @BindView(R.id.ac_setting_anche_shipin)
    Switch acSettingAncheShipin;
    @BindView(R.id.ac_setting_henandiqu)
    Switch acSettingHenandiqu;
    @BindView(R.id.ac_setting_haerbin)
    Switch acSettingHaerbin;
    @BindView(R.id.ac_setting_tianjin)
    Switch acSettingTianjin;
    @BindView(R.id.ac_setting_open_sign)
    Switch acSettingOpenSign;
    @BindView(R.id.ac_setting_video_quality)
    LinearLayout acSettingVideoQuality;
    @BindView(R.id.ac_setting_video_quality_txt)
    TextView acSettingVideoQualityTxt;
    @BindView(R.id.ac_setting_lushi_shoudong_paizhao)
    Switch acSettingLushiShoudongPaizhao;
    @BindView(R.id.ac_setting_hangzhou)
    Switch acSettingHangzhou;
    @BindView(R.id.ac_setting_yasuoPhoto)
    TextView acSettingYasuoPhoto;
    @BindView(R.id.ac_setting_waikuo_shipin)
    Switch acSettingWaikuoShipin;
    @BindView(R.id.ac_setting_dongbei)
    Switch acSettingDongbei;
    @BindView(R.id.ac_setting_neimenggu)
    Switch acSettingNeimenggu;
    @BindView(R.id.ac_setting_da_car)
    Switch acSettingDaCar;
    @BindView(R.id.ac_setting_yun_nan)
    Switch acSettingYunNan;
    @BindView(R.id.ac_setting_qingdao)
    Switch acSettingQingdao;
    @BindView(R.id.ac_setting_line_2)
    Switch acSettingLine2;
    @BindView(R.id.ac_setting_digou)
    Switch acSettingDigou;
    @BindView(R.id.ac_setting_road_qianyinli)
    Switch acSettingRoadQianyinli;

    //endregion
    //popuwindow
    private View popu_view;
    private View popu_provinces_view;
    private LinearLayout parent22;
    private RelativeLayout parent_view;
    private PopupWindow pop = null;
    private PopupWindow pop_provinces = null;
    private ListView listview_modes;
    private ListView listview_provinces;
    private List<String> strModes = new ArrayList<String>();
    private List<String> yes_no_Modes = new ArrayList<String>();
    private MyAccountModeListAdapter MyAccountModeListAdapter;
    private MyProvincesListAdapter myProAdapter;
    private String CURRENT_SELECT_TYPE = "否";
    private int SELECT_TYPE = 0;//:0：检测模式，，1：是否
    private int view_type = 0;//当前是第几个下拉列表
//    private boolean isChecked = false;

    private String IS_OPEN_SIGN = "是", login_username = "";
    //    private List<String> provinces_list = new ArrayList<String>();//省会简称列表
//    private List<String> letter_list = new ArrayList<String>();//字母列表
    SettingModel settingModel = new SettingModel();//保存系统设置的model

    private SettingActivity instance = null;
    private AlertDialog.Builder builder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        ButterKnife.bind(this);
        if (SharedPreferencesUtils.getIPModel(SettingActivity.this) != null) {
            UtilsLog.e("==" + SharedPreferencesUtils.getIPModel(this).toString());
        } else {
            UtilsLog.e("=SharedPreferencesUtils.getIPModel=null");
        }
        instance = this;
        setBackBtn();
        setTopTitle(R.string.title_activity_setting);
        login_username = getIntent().getExtras().getString("login_username", "");
        UtilsLog.e("login_username==" + login_username);
//        login_username = getIntent().getExtras().getString("login_username", BaseApplication.accountModelList.get(0).getUserName());
        String logStrf = "\n" + "onCreate-----系统设置-------" + "\n" +
                "视频画质==" + SharedPreferencesUtils.getVideoQuality(this) + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
        initData();
        pop_account();
        pop_provinces();

        UtilsLog.e("MoRenLine2==" + SharedPreferencesUtils.getMoRenLine2(this));
        UtilsLog.e("是否自动刷新==" + SharedPreferencesUtils.getAutoRefresh(this));
        UtilsLog.e("路试手动拍照==" + SharedPreferencesUtils.getLuShi_Shoudongpaizhao(this));

        UtilsLog.e("视频画质==" + SharedPreferencesUtils.getVideoQuality(this));
        acSettingVideoQualityTxt.setText(SharedPreferencesUtils.getVideoQuality(this));

        UtilsLog.e("是否压缩照片==" + SharedPreferencesUtils.getIsYasuoPhoto(this));
        acSettingYasuoPhoto.setText(SharedPreferencesUtils.getIsYasuoPhoto(this));
        acSettingYunNan.setChecked(SharedPreferencesUtils.getYunNan(this));
        UtilsLog.e("是否外扩视频录像==" + SharedPreferencesUtils.getWaiKuoVideo(this));
//        acSettingWaikuoShipin.setText(SharedPreferencesUtils.getWaiKuoVideo(this));
        // Line2
        acSettingLine2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferencesUtils.setMoRenLine2(instance, isChecked);
                acSettingLine2.setChecked(isChecked);//设置选中
            }
        });
        //路试牵引力
        acSettingRoadQianyinli.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferencesUtils.setRoadQianyinli(instance, isChecked);
                acSettingRoadQianyinli.setChecked(isChecked);//设置选中
            }
        });
        //是否外扩视频录像
        acSettingWaikuoShipin.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferencesUtils.setWaiKuoVideo(instance, isChecked);
                acSettingWaikuoShipin.setChecked(isChecked);//设置选中
            }
        });

        acSettingYunNan.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferencesUtils.setYunNan(instance, isChecked);
                acSettingYunNan.setChecked(isChecked);//设置选中
            }
        });


        if (SharedPreferencesUtils.getAutoRefresh(this)) {
            acSettingTxtMoren.setText("是");
        } else {
            acSettingTxtMoren.setText("否");
        }
        UtilsLog.e("管理员密码==" + SharedPreferencesUtils.getUserNickName(this));

//        UtilsLog.e("是否开启签名功能==" + SharedPreferencesUtils.getOpenSign(this));
//        if(SharedPreferencesUtils.getOpenSign(this)){
//            acSettingTxtSign.setText("是");
//        }else {
//            acSettingTxtSign.setText("否");
//        }
//        //路试手动拍照
//        acSettingLushiShoudongPaizhao.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//                SharedPreferencesUtils.setLuShi_Shoudongpaizhao(instance, isChecked);
//                acSettingLushiShoudongPaizhao.setChecked(isChecked);//设置选中
//            }
//        });
        //开启签名功能
        acSettingOpenSign.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferencesUtils.setOpenSign(instance, isChecked);
                acSettingOpenSign.setChecked(isChecked);//设置选中
            }
        });
//        //底盘动态拍照
//        acSettingDongtaiPaizhao.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//                SharedPreferencesUtils.setDongTaiPhoto(instance, isChecked);
//                acSettingDongtaiPaizhao.setChecked(isChecked);   //设置选中
//            }
//        });
        //切换队列样式
        acSettingListUi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferencesUtils.setPhotoClipping(instance, isChecked);
                acSettingListUi.setChecked(isChecked);   //设置选中
            }
        });
        //38900升级
        acSetting38900.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//                SharedPreferencesUtils.set38900(instance, isChecked);
                SharedPreferencesUtils.setCode2List(instance, isChecked);
                acSetting38900.setChecked(isChecked);   //设置选中
            }
        });
//        //新版本升级
//        acSettingXinShengji.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//                SharedPreferencesUtils.setNewVersionSwitch(instance, isChecked);
//                acSettingXinShengji.setChecked(isChecked);   //设置选中
//            }
//        });

        //绕车一周视频
        acSettingRaocheYizhou.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferencesUtils.setRaoCheYiZhouVideo(instance, isChecked);
                acSettingRaocheYizhou.setChecked(isChecked);   //设置选中
            }
        });

        //安车视频
        acSettingAncheShipin.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferencesUtils.setAnCheVideo(instance, isChecked);
                acSettingAncheShipin.setChecked(isChecked);   //设置选中
            }
        });

        //河南地区开关
        acSettingHenandiqu.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferencesUtils.setHeNanVersion(instance, isChecked);
                acSettingHenandiqu.setChecked(isChecked);   //设置选中
            }
        });
        //哈尔滨地区开关
        acSettingHaerbin.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferencesUtils.setHaErBinVersion(instance, isChecked);
                acSettingHaerbin.setChecked(isChecked);   //设置选中
                SharedPreferencesUtils.setDongTaiPhoto(instance, isChecked);
                SharedPreferencesUtils.setLuShi_Shoudongpaizhao(instance, isChecked);
            }
        });
        //内蒙古地区开关
        acSettingNeimenggu.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferencesUtils.setNeiMengGuVersion(instance, isChecked);
                acSettingNeimenggu.setChecked(isChecked);   //设置选中
            }
        });
        //东北地区开关
        acSettingDongbei.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferencesUtils.setDongBeiVersion(instance, isChecked);
                acSettingDongbei.setChecked(isChecked);   //设置选中
            }
        });
        //天津地区开关
        acSettingTianjin.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferencesUtils.setTianJinVersion(instance, isChecked);
                acSettingTianjin.setChecked(isChecked);   //设置选中
                SharedPreferencesUtils.setDongTaiPhoto(instance, isChecked);
            }
        });
        //杭州地区
        acSettingHangzhou.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferencesUtils.setHangZhouVersion(instance, isChecked);
                acSettingHangzhou.setChecked(isChecked);   //设置选中
            }
        });
        //青岛地区
        acSettingQingdao.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferencesUtils.setQingDao(instance, isChecked);
                acSettingQingdao.setChecked(isChecked);   //设置选中
            }
        });
        acSettingQingdao.setChecked(SharedPreferencesUtils.getQingDao(instance));
        UtilsLog.e("青岛地区==" + SharedPreferencesUtils.getQingDao(instance));
        //外检大车
        acSettingDaCar.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferencesUtils.setDaChe(instance, isChecked);
                acSettingDaCar.setChecked(isChecked);   //设置选中
            }
        });
        acSettingDaCar.setChecked(SharedPreferencesUtils.getDaChe(instance));
        UtilsLog.e("外检大车开关==" + SharedPreferencesUtils.getDaChe(instance));

        //地沟拍照开关
        acSettingDigou.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferencesUtils.setDiGou_PaiZhao(instance, isChecked);
                acSettingDigou.setChecked(isChecked);   //设置选中
            }
        });
        acSettingDigou.setChecked(SharedPreferencesUtils.getDiGou_PaiZhao(instance));
        UtilsLog.e("地沟拍照开关==" + SharedPreferencesUtils.getDiGou_PaiZhao(instance));

        acSettingHangzhou.setChecked(SharedPreferencesUtils.getHangZhouVersion(instance));
        UtilsLog.e("杭州地区开关==" + SharedPreferencesUtils.getHangZhouVersion(instance));
//        acSettingLushiShoudongPaizhao.setChecked(SharedPreferencesUtils.getLuShi_Shoudongpaizhao(instance));
        acSettingTianjin.setChecked(SharedPreferencesUtils.getTianJinVersion(instance));
        UtilsLog.e("天津地区开关==" + SharedPreferencesUtils.getTianJinVersion(instance));
        acSettingHaerbin.setChecked(SharedPreferencesUtils.getHaErBinVersion(instance));
        UtilsLog.e("哈尔滨地区开关==" + SharedPreferencesUtils.getHaErBinVersion(instance));
        acSettingNeimenggu.setChecked(SharedPreferencesUtils.getNeiMengGuVersion(instance));
        UtilsLog.e("内蒙古地区开关==" + SharedPreferencesUtils.getNeiMengGuVersion(instance));
        acSettingDongbei.setChecked(SharedPreferencesUtils.getDongBeiVersion(instance));
        UtilsLog.e("东北地区开关==" + SharedPreferencesUtils.getDongBeiVersion(instance));
        acSettingHenandiqu.setChecked(SharedPreferencesUtils.getHeNanVersion(instance));
        acSettingAncheShipin.setChecked(SharedPreferencesUtils.getAnCheVideo(instance));
        acSettingRaocheYizhou.setChecked(SharedPreferencesUtils.getRaoCheYiZhouVideo(instance));
        acSettingListUi.setChecked(SharedPreferencesUtils.getPhotoClipping(instance));
        acSettingOpenSign.setChecked(SharedPreferencesUtils.getOpenSign(instance));
//        UtilsLog.e("切换38900版本==" + SharedPreferencesUtils.get38900(instance));
        acSetting38900.setChecked(SharedPreferencesUtils.getCode2List(instance));

        acSettingLine2.setChecked(SharedPreferencesUtils.getMoRenLine2(instance));
        UtilsLog.e("路是牵引力开关==" + SharedPreferencesUtils.getRoadQianyinli(instance));
        acSettingRoadQianyinli.setChecked(SharedPreferencesUtils.getRoadQianyinli(instance));
//        UtilsLog.e("切换新版本升级==" + SharedPreferencesUtils.getNewVersionSwitch(instance));
//        acSettingXinShengji.setChecked(SharedPreferencesUtils.getNewVersionSwitch(instance));
//        acSettingDongtaiPaizhao.setChecked(SharedPreferencesUtils.getDongTaiPhoto(instance));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        String logStrf = "\n" + "onDestroy-----系统设置-------" + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
    }

    @OnClick({R.id.ac_setting_txt_moren, R.id.ac_set_btn_cancle,
            R.id.ac_set_btn_save, R.id.ac_setting_set_gaoji,
            R.id.ac_setting_video_quality, R.id.ac_setting_yasuoPhoto

    })
    public void onViewClicked(View view) {
        switch (view.getId()) {
//            case R.id.ac_setting_digou:
//                //地沟拍照开关
//                break;
            case R.id.ac_setting_video_quality:
                showMyDialog(he_ge_str, R.id.ac_setting_video_quality);
                break;
            case R.id.ac_setting_txt_moren:
                view_type = 3;
                SELECT_TYPE = 1;
                popuwindow_type();
                pop.showAtLocation(acSettingTxtMoren, Gravity.BOTTOM, 0, 0);
                break;
//            case R.id.ac_setting_txt_sign:
//
//                break;
            case R.id.ac_setting_yasuoPhoto:
                showMyDialog(ya_suo_str, R.id.ac_setting_yasuoPhoto);
                break;
            case R.id.ac_set_btn_cancle:
                logOut();
                finish();
                break;
            case R.id.ac_setting_set_gaoji:
                //高级设置
                showThree();
                break;
            case R.id.ac_set_btn_save:
                String imei = "";
                imei = acSettingEtJiqima.getText().toString().trim();
                String strIp = null;//ip
                String strPort = null;//端口号
                String file_strIp = null;//上传文件ip
                String file_strPort = null;//上传文件端口号
                String IsAutoRefresh = "是";//是否自动刷新
                IsAutoRefresh = acSettingTxtMoren.getText().toString().trim();

                strIp = acSettingEtIp.getText().toString().trim();
                strPort = acSettingEtPort.getText().toString().trim();
                file_strIp = acSettingEtIpFile.getText().toString().trim();
                file_strPort = acSettingEtPortFile.getText().toString().trim();
                if (!TextUtils.isEmpty(strIp) && !TextUtils.isEmpty(strPort) && !TextUtils.isEmpty
                        (file_strIp) && !TextUtils.isEmpty(file_strPort) && !TextUtils.isEmpty(imei)) {
//                    if (!TextUtils.isEmpty(strIp) && !TextUtils.isEmpty(strPort)) {
                    //端口号与IP地址不为空的前提下验证授权码
                    String ip_port = BASE_URL_front + strIp + ":" + strPort;
                    String file_ip_port = BASE_URL_front + file_strIp + ":" + file_strPort;
                    IPPortModel model = new IPPortModel();
                    model.setIp(strIp);
                    model.setIp_port(strPort);
                    model.setFile_ip(file_strIp);
                    model.setFile_ip_port(file_strPort);
                    SharedPreferencesUtils.setIPModel(this, model);

                    SharedPreferencesUtils.setIP(this, ip_port.trim());//一般请求接口的ip
                    SharedPreferencesUtils.setFileIP(this, file_ip_port.trim());//上传图片文件接口的ip
                    UtilsLog.e(SharedPreferencesUtils.getIPModel(this).toString().trim());
                    UtilsLog.e(SharedPreferencesUtils.getIP(this).toString().trim());
                    UtilsLog.e(SharedPreferencesUtils.getFileIP(this).toString().trim());

                    SharedPreferencesUtils.setIMEI(this, imei);
                    //是否自动刷新数据
                    if ("是".equals(IsAutoRefresh)) {
                        SharedPreferencesUtils.setAutoRefresh(this, true);
                    } else {
                        SharedPreferencesUtils.setAutoRefresh(this, false);
                    }
                    finish();
                } else {
                    Toast.makeText(this, R.string.activity_setting_ip_null, Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }

    /**
     * 三个按钮的 dialog
     */
    View three_view;

    private void showThree() {
        three_view = getLayoutInflater().inflate(R.layout.dialog_custom_base,
                null);
//        final TextView tv_left = (TextView)three_view.findViewById(R.id.dialog_my_left);
//        final TextView tv_middle = (TextView)three_view.findViewById(R.id.dialog_my_middle);
//        final TextView tv_right =(TextView) three_view.findViewById(R.id.dialog_my_right);
        final EditText etPassword = (EditText) three_view.findViewById(R.id.dialog_my_et_content);
        builder = new AlertDialog.Builder(this).setView(three_view)
//                .setTitle("管理员密码")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        String pwd = etPassword.getText().toString().trim();
                        if ("Savaboon123".equals(pwd)) {
                            //管理员密码正确
                            Intent advanceIntent = new Intent(instance, AdvanceSettingActivity.class);
                            startActivity(advanceIntent);
                        } else {
                            //管理员密码错误
                            Toast.makeText(mContext, "管理员密码错误", Toast.LENGTH_LONG).show();
                        }
                    }
                })
//                .setNeutralButton("忘记密码", new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialogInterface, int i) {
//                        Toast.makeText(mContext, "忘记密码", Toast.LENGTH_LONG).show();
//                    }
//                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        //ToDo: 你想做的事情
                        Toast.makeText(mContext, "取消", Toast.LENGTH_LONG).show();
                        dialogInterface.dismiss();
                    }
                });
        builder.create().show();

    }


    protected void initData() {
        for (int i = 0; i < Constants.MY_ACCOUNT_MODEL_LIST.length; i++) {
            strModes.add(i, Constants.MY_ACCOUNT_MODEL_LIST[i]);
        }
        for (int i = 0; i < Constants.YES_NO.length; i++) {
            yes_no_Modes.add(i, Constants.YES_NO[i]);
        }
        UtilsLog.e("iemi==" + SharedPreferencesUtils.getIMEI(this));
        if (!TextUtils.isEmpty(SharedPreferencesUtils.getIMEI(this))) {
            acSettingEtJiqima.setText(SharedPreferencesUtils.getIMEI(this));
        } else {
            String str0 = "", str1 = "";
            str0 = CommonUtils.getIMEI(this, 0);
            str1 = CommonUtils.getIMEI(this, 1);
            if (!TextUtils.isEmpty(str0) && str0 != "") {
                acSettingEtJiqima.setText(str0);
            } else {
                acSettingEtJiqima.setText(str1);
            }
        }

//        acSettingEtJiqima.setText(CommonUtils.getIMEI(this));
        if (SharedPreferencesUtils.getIPModel(SettingActivity.this) != null) {
            acSettingEtIp.setText(SharedPreferencesUtils.getIPModel(this).getIp());
            acSettingEtPort.setText(SharedPreferencesUtils.getIPModel(this).getIp_port());
            acSettingEtIpFile.setText(SharedPreferencesUtils.getIPModel(this).getFile_ip());
            acSettingEtPortFile.setText(SharedPreferencesUtils.getIPModel(this).getFile_ip_port());
            UtilsLog.e(SharedPreferencesUtils.getIPModel(this).toString());
        }


    }

    private void pop_account() {
        pop = new PopupWindow(this);
        popu_view = getLayoutInflater().inflate(R.layout.item_setting_popupwindows,
                null);
        pop.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
        pop.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        pop.setBackgroundDrawable(new BitmapDrawable());
        pop.setFocusable(true);
        pop.setOutsideTouchable(true);
        pop.setContentView(popu_view);
        listview_modes = (ListView) popu_view.findViewById(R.id.setting_listview);
    }

    private void pop_provinces() {
        pop_provinces = new PopupWindow(this);
        popu_provinces_view = getLayoutInflater().inflate(R.layout.item_setting_province_letter,
                null);
        pop_provinces.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        pop_provinces.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        pop_provinces.setBackgroundDrawable(new BitmapDrawable());
        pop_provinces.setFocusable(true);
        pop_provinces.setOutsideTouchable(true);
        pop_provinces.setContentView(popu_provinces_view);
        parent22 = (LinearLayout) popu_provinces_view.findViewById(R.id.setting_provinces_parent);
        listview_provinces = (ListView) popu_provinces_view.findViewById(R.id.setting_provinces_listview2);
        parent22.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                pop_provinces.dismiss();
            }
        });
    }

    private void popuwindow_type() {
        if (SELECT_TYPE == 0) {
            //检测模式
            MyAccountModeListAdapter = new MyAccountModeListAdapter(this, strModes);
        } else {
            //是否
            MyAccountModeListAdapter = new MyAccountModeListAdapter(this, yes_no_Modes);
        }
        listview_modes.setAdapter(MyAccountModeListAdapter);
        listview_modes.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        switch (SELECT_TYPE) {
            case 0:
                //检测模式
                CURRENT_SELECT_TYPE = strModes.get(position);
                break;
            case 1:
                //是否
                CURRENT_SELECT_TYPE = yes_no_Modes.get(position);
                break;
        }
        switch (view_type) {
            case 3:
                settingModel.setJiance_xiangmu_moren(CURRENT_SELECT_TYPE);
                acSettingTxtMoren.setText(CURRENT_SELECT_TYPE);
                break;
//            case 4:
//                settingModel.setBianma(CURRENT_SELECT_TYPE);
//                acSettingTxtBianma.setText(CURRENT_SELECT_TYPE);
//                break;
//            case 5:
//                settingModel.setShijian_xianzhi(CURRENT_SELECT_TYPE);
//                acSettingTxtShijian.setText(CURRENT_SELECT_TYPE);
//                break;
//            case 6:
//                settingModel.setPhoto_clip(CURRENT_SELECT_TYPE);
//                acSettingTxtPaizhao.setText(CURRENT_SELECT_TYPE);
//                break;
        }
        pop.dismiss();
    }

    //    private String[] he_ge_str = new String[]{"无","低", "中", "高", "最高"};
    private String[] he_ge_str = new String[]{"无", "低", "中", "高"};
    private String[] ya_suo_str = new String[]{"是", "否"};

    private void showMyDialog(String[] str, final int id) {
        BottomMenu.show(this, str, new OnMenuItemClickListener() {
            @Override
            public void onClick(String text, int index) {
                //返回参数 text 即菜单名称，index 即菜单索引
                UtilsLog.e("设置---showMyDialog==" + text + "===" + index);
                switch (id) {
                    case R.id.ac_setting_video_quality:
                        /**
                         * 0: 低   1：中   2：高
                         * */
                        acSettingVideoQualityTxt.setText(text);
                        SharedPreferencesUtils.setVideoQuality(SettingActivity.this, text);
                        break;
                    case R.id.ac_setting_yasuoPhoto:
                        acSettingYasuoPhoto.setText(text);
                        SharedPreferencesUtils.setIsYasuoPhoto(SettingActivity.this, text);
                        break;
//                    case R.id.ac_online_online:
////                        acOnlineOnline.setText(text);
//                        break;
                }
            }
        }).setMenuTextInfo(new TextInfo().setBold(true).setFontColor(Color.BLACK).setGravity(Gravity.CENTER));
    }


    //退出登录
    private void logOut() {
        String logout_url = "/api/User/" + login_username + "/UserQuitID";
        UtilsLog.e("退出登录---url==" + SharedPreferencesUtils.getIP(instance) + logout_url);
        String logStr = "\n" + "退出登录----" + "\n" + "URL::" +
                SharedPreferencesUtils.getIP(instance) + logout_url + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>get(SharedPreferencesUtils.getIP(instance) + logout_url).tag(instance)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        WaitDialog.show(instance, "加载中...");
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
//                        CommonUtils.hideLoadingDialog(instances);
                        String result = response.body();
//                        UtilsLog.e("getDataUsersList-result==" + result);
//                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("退出登录-newResult==" + result);
//                        String logStr = "\n" + "获取用户列表--getDataUsersList----onSuccess" + "\n" + "URL::" +
//                                SharedPreferencesUtils.getIP(instances) +
//                                GETALLUSERS + "\n" + "result::" + result + "\n";
//                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
//                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
//                                (newResult) && !"[]".equals(result)) {
//
//                            try {
//                                BaseApplication.userAccountModelList = JsonUtil.stringToArray(newResult,
//                                        UserAccountModel[].class);
//                                //0  3  4  6
//                                if (BaseApplication.userAccountModelList != null && BaseApplication.userAccountModelList.size() > 0) {
//
//                                }
//                            } catch (Exception e) {
//                                UtilsLog.e("退出登录t-Exception==" + e.getMessage());
//                            }
//                        } else {
////                            Toast.makeText(instances, getResources().getString(R.string.network_error),
//// Toast.LENGTH_LONG).show();
//                            UtilsLog.e("退出登录-result==" + "没有数据");
//                        }
                        WaitDialog.dismiss();
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        WaitDialog.dismiss();
//                        CommonUtils.hideLoadingDialog(instances);
                        String logStr = "\n" + "退出登录----onError" + "\n" + "URL::" +
                                SharedPreferencesUtils.getIP(instance) +
                                logout_url + "\n" + "result::" + response.body() + "\n";
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        UtilsLog.e("退出登录-onError==" + response.body());

//                        Toast.makeText(instances, "读取人员列表失败，请退出重试", Toast
//                                .LENGTH_LONG).show();
                    }
                });
    }


}
